package main

import (
	"fmt"
	"ghw2/server/config"
	"ghw2/server/redis"
	"math/rand"
)

func main() {
	config.ServerConfigInit("G:\\code\\go\\ghw2\\grpchomework\\server\\server.yaml")
	redis.InitRedis()
	conn := redis.RedisPool.Get()

	reply, _ := conn.Do("SET", "locker", "1", "EX", "10", "NX")
	fmt.Println(reply)
	reply, _ = conn.Do("get", "locker")
	fmt.Println(string(reply.([]byte)))

	reply, _ = conn.Do("evalsha", config.ServerConfig.RedisLuaSha, 1, "locker", "1")
	fmt.Println(reply)

	reply, _ = conn.Do("get", "locker")
	if reply != nil {
		fmt.Println(string(reply.([]byte)))
	} else {
		fmt.Println(reply)
	}

	fmt.Println("------------------")
	reply, _ = conn.Do("SET", "book:sad:5", "1", "EX", "10", "NX")
	fmt.Println(reply)
	reply, _ = conn.Do("keys", "book:*a*")
	fmt.Println(reply)
	if reply != nil {
		key := reply.([]interface{})[0].([]byte)
		fmt.Println(string(key))
		key2 := reply.([]interface{})
		fmt.Printf("%k\n", key2)
	}

	fmt.Println(rand.Int63n(114512))

	conn.Close()
}
